clear all
set more off , permanently
capture log close


********************************************************************************
********** This file creates descriptive price plots for Bavaria ***************
********************************************************************************

******************************************************
******************* Load data ************************
******************************************************

	// Load price panel	
		cd "$dta" 
		use germany_prices_5pm.dta, clear  
		
	// Keep Bavaria
		keep if state == 9	

	// Add radio treatment information
		rename station_id id_data 
		merge m:1 id_data using "$dta\treated_petrol_stations.dta"

	// Generate treatment variable
		gen treated = 0
		replace treated = 1 if ///
		(treated_6157 == "yes" & date >= date("20140425","YMD")) | /// 
		(treated_6166 == "yes" & date >= date("20130601","YMD") & date < date("20170726","YMD")) | ///
		(treated_6167 == "yes" & date >= date("20130601","YMD") & date < date("20170726","YMD")) | ///
		(treated_6424 == "yes" & date >= date("20140202","YMD") & date < date("20170305","YMD"))

		drop _merge

	// Label variables
		label var treated "Is petrol station treated at particular period in time?"
		foreach X of num 6157 6166 6167 6424{
		label var treated_`X' "Is petrol station ever treated by reports of radio station `X'?"
		}
		
	// Specify panel structure
		encode id_data , g(station_id)
		xtset station_id date	
		
	// Save data
		save bavaria_prices_9125_v1.dta, replace
	

	// Radio ID 
		* Radio Arabella: id == 6157		
		* Extra-Radio: id == 6424
		
		
************************************************************************ 
****        Table 5: petrol    (effect on log gross price)          ****
************************************************************************ 

eststo clear


/////// Extra-Radio only ///////

// 1. FE regression dropping all petrol stations ever treated, that are not treated by Extra-Radio //
	cd "$dta"
	use bavaria_prices_9125_v1.dta , clear

	* Keep only for restricted analysis period (this can be adapted, but note that we don't have refinery prices after August 2014)
		keep if date>=date("20131001","YMD") & date<date("20140901","YMD")

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
			
	* Drop stations that are in Radio Arabella reception area or in reception area of Rosenheim stations
		drop if treated_6166=="yes" | treated_6167=="yes" | treated_6157=="yes"
		
			** Save a list of station ids in the reception area of Extra-Radio for placebo check in the .do file #36
			preserve 
				keep if treated==1
				keep id_data
				rename id_data station_id
				duplicates drop
				gen extra_radio = 1
				save "$dta\temp_extra_radio_id", replace
			restore 
		
	* Gen log price at 5 pm
		gen log_price = log(e5_17oclock_panel)	

	* Carry out regressions on retail margins
		eststo price_fe_17_extra: quietly reghdfe log_price treated , absorb(i.date i.station_id) vce(cl station_id)
		estadd ysumm
		

/////// Radio Arabella only ///////

// 2. FE regression dropping all petrol stations ever treated, that are not treated by Radio Arabella //
	cd "$dta"
	use bavaria_prices_9125_v1.dta , clear

	* Keep only for restricted analysis period (this can be adapted, but note that we don't have refinery prices after August 2014)
		keep if date>=date("20131001","YMD") & date<date("20140901","YMD")

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
			
	* Drop stations that are in Extra-Radio reception area or in reception area of Rosenheim stations
		drop if treated_6166 == "yes" | treated_6167 == "yes" | treated_6424 == "yes"
		
	* Gen log price at 5 pm
		gen log_price = log(e5_17oclock_panel)	

	* Carry out regressions on retail margins
		eststo price_fe_17_arabella: quietly reghdfe log_price treated , absorb(i.date i.station_id) vce(cl station_id)
		estadd ysumm

		
		
************************************************************************ 
****        Table 5: diesel    (effect on log gross price)          ****
************************************************************************ 

/////// Extra-Radio only ///////

// 3. FE regression dropping all petrol stations ever treated, that are not treated by Extra-Radio //
	cd "$dta"
	use bavaria_prices_9125_v1.dta , clear

	* Keep only for restricted analysis period (this can be adapted, but note that we don't have refinery prices after August 2014)
		keep if date>=date("20131001","YMD") & date<date("20140901","YMD")

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
			
	* Drop stations that are in Radio Arabella reception area or in reception area of Rosenheim stations
		drop if treated_6166=="yes" | treated_6167=="yes" | treated_6157=="yes"
		
	* Gen log price at 5 pm
		gen log_price = log(gazole_17oclock_panel)	

	* Carry out regressions on retail margins
		eststo price_fe_17_extra_d: quietly reghdfe log_price treated , absorb(i.date i.station_id) vce(cl station_id)
		estadd ysumm
		

/////// Radio Arabella only ///////

// 4. FE regression dropping all petrol stations ever treated, that are not treated by Radio Arabella //
	cd "$dta"
	use bavaria_prices_9125_v1.dta , clear

	* Keep only for restricted analysis period (this can be adapted, but note that we don't have refinery prices after August 2014)
		keep if date>=date("20131001","YMD") & date<date("20140901","YMD")

	* Drop dates after the introduction of the MTU with a temporary (1-3 day) drop of notifications of more than 40%
			drop if date == d(29nov2013) | date == d(10dec2013) | date == d(22dec2013) | date == d(01jan2014) | date == d(29aug2014) | date == d(01sep2014)
			drop if date >= d(08nov2014) & date <= d(11nov2014)
			
	* Drop stations that are in Extra-Radio reception area or in reception area of Rosenheim stations
		drop if treated_6166 == "yes" | treated_6167 == "yes" | treated_6424 == "yes"
		
	* Gen log price at 5 pm
		gen log_price = log(gazole_17oclock_panel)	

	* Carry out regressions on retail margins
		eststo price_fe_17_arabella_d: quietly reghdfe log_price treated , absorb(i.date i.station_id) vce(cl station_id)
		estadd ysumm

		
	* Gen Table 5: Effect of radio reports on the logarithm of gross prices
		esttab price_fe_17_extra price_fe_17_arabella price_fe_17_extra_d price_fe_17_arabella_d using "$output\Table 5_regression_both_extr_arabella_loggrossprice.tex" , b(4) se(4) ar2 replace booktabs keep(treated) star(* 0.10 ** 0.05 *** 0.01) label ///
		title(Effect of radio reports on the logarithm of gross prices) ///
		nonumbers mtitles("(1)E5 \textit{Extra-Radio}" "(2)E5 \textit{Radio Arabella}" "(3)Diesel \textit{Extra-Radio}" "(4)Diesel \textit{Radio Arabella}") ///
		addnote("SEs are clustered at the fuel station level.")		
		
		
// Erase data 
erase bavaria_prices_9125_v1.dta 		
		